package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.service.impl.OrderServiceImpl;
import com.sky.vo.OrderStatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
    PageResult page = ordersService.ConditionSerachPage(ordersPageQueryDTO);
    return Result.success(page);
    }

    @GetMapping("/statistics")
    public Result statistics() {
        OrderStatisticsVO orderStatisticsVO = ordersService.getStatusStatistics();
        return Result.success(orderStatisticsVO);
    }
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        ordersService.confrimOrder(ordersConfirmDTO.getId());
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id) {
        ordersService.deliveryOrder(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        ordersService.completeOrder(id);
        return Result.success();
    }
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        ordersService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }
    @GetMapping("/details/{id}")
    public Result details(@PathVariable Long id) {
        return Result.success(ordersService.orderDetail(id));
    }
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        ordersService.cancel(ordersCancelDTO);
        return Result.success();
    }
}
